package com.tangkun.environment.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

/**
 * JumpHelper[v 1.0.0]
 * classes:com.yixin.oaoinventory.utils.JumpHelper
 *
 * @author zhoujinjie
 * @date 2016/4/7
 * @time 19:23
 * @description 界面跳转工具类
 */
public class JumpHelper {
    /**
     * 跳转到一个新的activity，当前activity finish
     *
     * @param context
     * @param activityClass
     */
    @SuppressWarnings("rawtypes")
    public static void jump(Activity context, Class activityClass) {
        Intent intent = new Intent(context, activityClass);
        jump(context, intent, true);
    }

    /**
     * 跳转到一个新的activity，当前activity根据finish判断是否结束
     *
     * @param context
     * @param activityClass
     * @param isFinish
     */
    @SuppressWarnings("rawtypes")
    public static void jump(Activity context, Class activityClass,
                            boolean isFinish) {
        Intent intent = new Intent(context, activityClass);
        jump(context, intent, isFinish);
    }

    /**
     * 传参跳转
     *
     * @param context
     * @param intent
     * @param isFinish
     */
    public static void jump(Activity context, Intent intent, boolean isFinish) {
        context.startActivity(intent);
        // context.overridePendingTransition(R.anim.scale_in, R.anim.scale_out);
        if (isFinish) {
            context.finish();
        }
    }

    /**
     * 需要有结果返回
     *
     * @param context
     * @param intent
     * @param isFinish
     */
    public static void jumpForResult(Activity context, Intent intent,
                                     int reqCode, boolean isFinish) {
        context.startActivityForResult(intent, reqCode);
        // context.overridePendingTransition(R.anim.scale_in, R.anim.scale_out);
        if (isFinish) {
            context.finish();
        }
    }

    /**
     * 关闭当前activity
     *
     * @param context
     */
    public static void finish(Context context) {
        if (context instanceof Activity) {
            ((Activity) context).finish();
        }

    }
}
